package cn.eyesea.cc.frame.base;

import cn.eyesea.cc.config.GlobalConfig;
import cn.eyesea.cc.frame.context.AssemblyRealizeContext;
import cn.eyesea.cc.frame.enums.LogicalLayerTypeEnum;
import cn.eyesea.cc.frame.enums.LogicalTypeEnum;

import java.util.List;

/**
 * 组件
 *
 * @author wanghuilong
 * @version 1.0
 * @date 2021/6/27 4:11 下午
 */
public abstract class Assembly {


    /**
     * 逻辑类型
     *
     * @return
     */
    public abstract LogicalTypeEnum getLogicalType();


    /**
     * 依赖逻辑类型list
     *
     * @return
     */
    public abstract List<LogicalTypeEnum> relyLogicalTypes();

    /**
     * 组件实现
     *
     * @param assemblyRealizeContext
     * @return
     */
    public abstract ResultResource realize(AssemblyRealizeContext assemblyRealizeContext);

    /**
     * 组件依赖实现
     *
     * @param assemblyRealizeContext
     * @return
     */
    public abstract ResultResource relyRealize(AssemblyRealizeContext assemblyRealizeContext);

    public String createPackage(LogicalLayerTypeEnum logicalLayer, GlobalConfig globalConfig) {
        String packageInfo = logicalLayer.getPackageInfo();
        String logicalTypeStr = getLogicalType().name().toLowerCase();
        return new StringBuilder(globalConfig.getBasePackage()).append(".").append(packageInfo)
                .append(".").append(logicalTypeStr).toString();
    }

    public String createResourcePath(ResultResource resultResource, GlobalConfig globalConfig) {
        return new StringBuilder(globalConfig.getBaseDir()).append("/").append(resultResource.getPackageInfo().replaceAll("\\.", "/"))
                .append("/").append(resultResource.getName()).append(resultResource.getResourceType().getFilExtension()).toString();
    }

}
